home *** CD-ROM | disk | FTP | other *** search
/ CD-ROM Data 2002 May / CD Rom Data Mayıs 2002.iso / Freeware / Blitz Basic / data1.cab / Support / help / samples / particles.bb < prev    next >
Encoding:
Text File  |  2002-04-10  |  1.1 KB  |  67 lines

  1.  
  2. AppTitle "***** Particles *****"
  3.  
  4. Const max_particles=700    ;play with this!!!!!
  5.  
  6. Const width=640,height=480,gravity#=.075
  7.  
  8. Global count
  9.  
  10. Type Particle
  11.     Field x#,y#
  12.     Field xs#,ys#
  13.     Field w,h,r,g,b
  14. End Type
  15.  
  16. Graphics width,height
  17. SetBuffer BackBuffer()
  18.  
  19. Setup( width/2 )
  20.  
  21. Repeat
  22.     Cls
  23.     Update()
  24.     Render()
  25. ;    Rect 0,ScanLine(),width,1
  26.     Flip
  27. Until KeyDown(1)
  28.  
  29. End
  30.  
  31. Function Setup( x )
  32.     If count>=max_particles Then Return
  33.     p.Particle=New Particle
  34.     p\w=Rnd( 5 )+5:p\h=Rnd( 5 )+5
  35.     p\x=x:p\y=height-30
  36.     p\xs=Rnd( -2,2 ):p\ys=Rnd( -8,-5 )
  37.     p\r=255:p\g=255:p\b=255
  38.     count=count+1
  39. End Function
  40.  
  41. Function Update()
  42.     For p.Particle=Each Particle
  43.         p\x=p\x+p\xs
  44.         If p\x<0 Or p\x>width-p\w
  45.             p\xs=-p\xs
  46.             p\x=p\x+p\xs
  47.         EndIf
  48.         p\ys=p\ys+gravity:p\y=p\y+p\ys
  49.         If p\y>height-p\h And p\ys>0 Then Setup( p\x ):p\ys=-p\ys
  50.         If p\b>0
  51.             p\b=p\b-5
  52.         Else If p\g>0 
  53.             p\g=p\g-5
  54.         Else If p\r>0
  55.             p\r=p\r-1
  56.         Else 
  57.             Delete p:count=count-1
  58.         EndIf
  59.     Next
  60. End Function
  61.  
  62. Function Render()
  63.     For p.Particle=Each Particle
  64.         Color p\r,p\g,p\b
  65.         Rect p\x,p\y,p\w,p\h
  66.     Next
  67. End Function